package cn.csc.module.order.util;

import com.alibaba.nacos.shaded.com.google.gson.Gson;
import com.kuaidi100.sdk.api.QueryTrack;
import com.kuaidi100.sdk.core.IBaseClient;
import com.kuaidi100.sdk.pojo.HttpResult;
import com.kuaidi100.sdk.request.QueryTrackParam;
import com.kuaidi100.sdk.request.QueryTrackReq;
import com.kuaidi100.sdk.utils.SignUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;


@Slf4j
@Configuration
public class Kuaidi100Util {
    @Value("${csc.wl.kuaidi100.customer}")
    private String customer1;
    @Value("${csc.wl.kuaidi100.key}")
    private String key1 ;

    public HttpResult queryTrack (String customer,String key,String com,String num ) {
        log.info("[Kuaidi100Util][customer][key]{}{}{}",customer,key);
        QueryTrackReq queryTrackReq = new QueryTrackReq();
        QueryTrackParam queryTrackParam = new QueryTrackParam();
        queryTrackParam.setCom(com);
        queryTrackParam.setNum(num);
        String param = new Gson().toJson(queryTrackParam);

        queryTrackReq.setParam(param);
        queryTrackReq.setCustomer(customer);
        log.info("[Kuaidi100Util][param]{}",param);
        log.info("[Kuaidi100Util][customer]{}{}{}",customer1,key1);
        queryTrackReq.setSign(SignUtils.querySign(param ,key,customer));
        log.info("[Kuaidi100Util][Sign]{}",SignUtils.querySign(param ,key,customer));
        IBaseClient baseClient = new QueryTrack();
        try {
            return baseClient.execute(queryTrackReq);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
